package reading.common.pojos;

import lombok.Data;
import reading.common.enums.ErrorEnum;
import reading.common.enums.IBaseEnum;

/**
 * ${DESCRIPTION}
 *
 * @author txw
 * @since 2018-12-21 15:15
 **/
@Data
public class EntityResponse<T> {
    private int errCode;
    private String errMsg;
    private T data;

    public EntityResponse() {
    }

    public EntityResponse(int errCode, String errMsg, T data) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.data = data;
    }

    public static <T> EntityResponse<T> error(IBaseEnum iBaseEnum) {
        return new EntityResponse<>(iBaseEnum.getValue(), iBaseEnum.getName(),null);
    }

    public static <T> EntityResponse<T> nullData() {
        return new EntityResponse<>(ErrorEnum.NOT_FIND_DATA.getValue(), ErrorEnum.NOT_FIND_DATA.getName(), null);
    }

    public static <T>  EntityResponse<T> success(T data) {
        return new EntityResponse<>(ErrorEnum.SUCCESS.getValue(), ErrorEnum.SUCCESS.getName(), data);
    }

    public static <T>  EntityResponse<T> success() {
        return new EntityResponse<>(ErrorEnum.SUCCESS.getValue(), ErrorEnum.SUCCESS.getName(), null);
    }

    public static <T> EntityResponse<T> authBeond() {
        return new EntityResponse<>(ErrorEnum.AUTH_BEYOND.getValue(), ErrorEnum.AUTH_BEYOND.getName(), null);
    }
}
